package me.sauce.folkpocket48.home

import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.OnLifecycleEvent
import android.util.Log
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.rxkotlin.subscribeBy
import io.reactivex.schedulers.Schedulers
import me.sauce.folkpocket48.data.DataResponse


/**
 * @author sauceWu .
 * @since 2017/12/21 11:07
 */
class LifeModule(private val view: LifeActivity) : LifecycleObserver {

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    fun create() {
        val list = listOf("Alpha", "Beta", "Gamma", "Delta", "Epsilgit on")
        Log.e("1", System.currentTimeMillis().toString())
        DataResponse.data.testDao().queryAll()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeBy(  // named arguments for lambda Subscribers
                        onNext = {
                            Log.e("onNext", System.currentTimeMillis().toString())
                            val sb = StringBuilder()
                            it.forEach {
                                sb.append(it)
                                sb.append("\n")
                            }
                            view.setViewHole(HomeViewModule(sb.toString()))
                            Log.e("onNext1", System.currentTimeMillis().toString())
                        },
                        onError = { it.printStackTrace() },
                        onComplete = {
                            Log.e("onComplete", System.currentTimeMillis().toString())
                        }
                )


    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    fun start() {

//        LoginManager.isDebug = true
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    fun resume() {

    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    fun pause() {


    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    fun stop() {


    }

}
